package com.ccys.cms.controller.consultation;

import com.ccys.cms.service.consultation.ConsultationOrderAndListService;
import com.ccys.common.vo.ResponseResult;
import com.ccys.db.dto.consultation.*;
import com.ccys.db.vo.consultation.*;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.yaml.snakeyaml.error.Mark;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.text.ParseException;
import java.util.List;

/**
 * @program: WhiteCoat
 * @description: 问诊订单和列表接口
 * @author: ZhangJingCan
 * @create: 2023-12-27 15:13
 **/

@RestController
@RequestMapping("consultation")
@Api(tags = "consultation-问诊订单和列表接口")
public class ConsultationOrderAndListController {

    @Autowired
    private ConsultationOrderAndListService consultationOrderAndListService;

    @GetMapping("consultation/basePage")
    @ApiOperation("分页查询问诊(通用)")
    public ResponseResult<PageInfo<ConsultationPageQueryVo>, BigDecimal> findConsultationBasePage(ConsultationPageQueryDto dto) {
        return consultationOrderAndListService.findConsultationBasePage(dto);
    }

    @GetMapping("consultation/findGroupList")
    @ApiOperation("问诊页面的On going consultations里面的分组查询，All通过循环相加集合内的number得出")
    public ResponseResult<List<ConsultationGroupMake>, Integer> findConsultationGroupList() {
        return consultationOrderAndListService.findConsultationGroupList();
    }

    @PutMapping("consultation/updateConsultationHide")
    @ApiOperation("问诊页面的Hide修改(Consultation list和Deleted consultation list通用)")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "booking的ID", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "hideFromPatient", value = "隐藏问诊：0-不隐藏,1-隐藏", required = true, dataType = "string", paramType = "query"),
    })
    public ResponseResult updateConsultationHide(@ApiIgnore BookingDTO dto) {
        return consultationOrderAndListService.updateConsultationHide(dto);
    }

    @DeleteMapping("consultation/deleteConsultation")
    @ApiOperation("问诊页面的删除(Consultation list和Deleted consultation list通用)")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "booking的ID", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "deleteReason", value = "第一次删除的理由,判断deleted为0的时候点击删除则必须传入这个删除理由", required = false, dataType = "string", paramType = "query"),
    })
    public ResponseResult deleteConsultation(@ApiIgnore BookingDTO dto) {
        return consultationOrderAndListService.deleteConsultation(dto);
    }

    @PutMapping("consultation/updateDel")
    @ApiOperation("问诊页面的恢复删除")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "booking的ID", required = true, dataType = "string", paramType = "query"),
    })
    public ResponseResult updateDel(@ApiIgnore BookingDTO dto) {
        return consultationOrderAndListService.updateDel(dto);
    }


//    @GetMapping("doctorInfo/consultationList/page")
//    @ApiOperation("医生info的consultationList分页列表")
//    public ResponseResult<PageInfo<DoctorInfoConsultationListPageVo>, BigDecimal> findPageDoctorInfoConsultationList(DoctorInfoConsultationListPageDto dto) {
//        return consultationOrderAndListService.findPageDoctorInfoConsultationList(dto);
//    }

    @GetMapping("consultation/consultationGraph")
    @ApiOperation("统计图(医生info也使用这个接口，但是医生那边必须传入医生ID)")
    public ResponseResult<List<ConsultationGraphQueryVo>, BigDecimal> findConsultationGraph(ConsultationGraphQueryDto dto) {
        return consultationOrderAndListService.findConsultationGraph(dto);
    }

    //mark as packed(打包药物):将status从5改为6
    @PutMapping("consultation/order/markAsPacked")
    @ApiOperation("问诊订单的Action按钮的mark as packed")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "booking的ID", required = true, dataType = "string", paramType = "query"),
    })
    public ResponseResult updateConsultationOrderMarkAsPacked(@ApiIgnore BookingDTO dto) {
        return consultationOrderAndListService.updateConsultationOrderMarkAsPacked(dto);
    }

    //mark as completed(完成问诊):将status改为99
    @PutMapping("consultation/order/markAsCompleted")
    @ApiOperation("问诊订单的Action按钮的mark as completed")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "booking的ID", required = true, dataType = "string", paramType = "query"),
    })
    public ResponseResult updateConsultationOrderMarkAsCompleted(@ApiIgnore BookingDTO dto) {
        return consultationOrderAndListService.updateConsultationOrderMarkAsCompleted(dto);
    }

    //4.Schedule Grab(用 Grab快递进行配送):选择一个pick up time,修改expressType为1 ,在tbl_booking_grab添加一条数据(后续的定时任务或者是回调会把sub_status改为1)
    //新生成的tbl_booking_grab的status为1 - 作废时改为-2
    @PutMapping("consultation/order/scheduleGrab")
    @ApiOperation("问诊订单的Action按钮的Schedule Grab")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "booking的ID", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "pickUpTime", value = "pickUpTime选择的收货时间", required = true, dataType = "string", paramType = "query"),
            //todo:instructionUrl每次生成都是不同的url地址，不知道是什么(猜测为回调地址)
            @ApiImplicitParam(name = "instructionUrl", value = "待确认是什么", required = true, dataType = "string", paramType = "query"),
    })
    public ResponseResult updateConsultationOrderScheduleGrab(@ApiIgnore BookingGrabDto dto) {
        return consultationOrderAndListService.updateConsultationOrderScheduleGrab(dto);
    }

    //5.Re-schedule Grab(在定时任务扫到pick up time之前可以重新修改时间):重复上一步的操作，作废之前的grab记录
    @PutMapping("consultation/order/reScheduleGrab")
    @ApiOperation("问诊订单的Action按钮的Re-schedule Grab")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "bookingId", value = "booking的ID", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "pickUpTime", value = "pickUpTime选择的收货时间", required = true, dataType = "string", paramType = "query"),
            //todo:instructionUrl每次生成都是不同的url地址，不知道是什么(猜测为回调地址)
            @ApiImplicitParam(name = "instructionUrl", value = "待确认是什么", required = true, dataType = "string", paramType = "query"),
    })
    public ResponseResult updateConsultationOrderReScheduleGrab(@ApiIgnore BookingGrabDto dto) {
        return consultationOrderAndListService.updateConsultationOrderReScheduleGrab(dto);
    }

    //6.Cancel grab delivery(取消grab快递):修改sub_status为0，expressType为0，作废grab记录
    @PutMapping("consultation/order/cancelGrabDelivery")
    @ApiOperation("问诊订单的Action按钮的Cancel grab delivery")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "bookingId", value = "booking的ID", required = true, dataType = "string", paramType = "query"),
    })
    public ResponseResult updateConsultationOrderCancelGrabDelivery(@ApiIgnore BookingGrabDto dto) {
        return consultationOrderAndListService.updateConsultationOrderCancelGrabDelivery(dto);
    }

    //7.Schedule Uparcel express(使用uparcel特快):选择一个pick up time,修改expressType为2,在tbl_Booking_uParcel添加一条数据(后续定时任务或者回调改变sub_status为1)
    @PutMapping("consultation/order/scheduleUparcelExpress")
    @ApiOperation("问诊订单的Action按钮的Schedule Uparcel express")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "bookingId", value = "booking的ID", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "bookingCode", value = "booking的code", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "pickUpTime", value = "选择的时间", required = true, dataType = "string", paramType = "query"),
    })
    public ResponseResult updateConsultationOrderScheduleUparcelExpress(@ApiIgnore BookingUparcelDto dto) {
        return consultationOrderAndListService.updateConsultationOrderScheduleUparcelExpress(dto);
    }

    //8.Cancel uparcel delivery(取消uparcel快递):类似取消grab的操作
    @PutMapping("consultation/order/cancelUparcelDelivery")
    @ApiOperation("问诊订单的Action按钮的Cancel uparcel delivery")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "bookingId", value = "booking的ID", required = true, dataType = "string", paramType = "query"),
    })
    public ResponseResult updateConsultationOrderCancelUparcelDelivery(@ApiIgnore BookingUparcelDto dto) {
        return consultationOrderAndListService.updateConsultationOrderCancelUparcelDelivery(dto);
    }

    //9.Re-schedule uParcel(重新使用uparcel快递):类似grab
    @PutMapping("consultation/order/reScheduleUParcel")
    @ApiOperation("问诊订单的Action按钮的Re-schedule uParcel")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "bookingId", value = "booking的ID", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "bookingCode", value = "booking的code", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "pickUpTime", value = "选择的时间", required = true, dataType = "string", paramType = "query"),
    })
    public ResponseResult updateConsultationOrderReScheduleUParcel(@ApiIgnore BookingUparcelDto dto) {
        return consultationOrderAndListService.updateConsultationOrderReScheduleUParcel(dto);
    }


    //10.Schedule Uparcel standard(使用uparcel普通):自动计算pick up时间，后续类似上述步骤
    @PutMapping("consultation/order/scheduleUparcelStandard")
    @ApiOperation("问诊订单的Action按钮的Schedule Uparcel standard")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "bookingId", value = "booking的ID", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "bookingCode", value = "booking的code", required = true, dataType = "string", paramType = "query"),
    })
    public ResponseResult updateConsultationOrderScheduleUparcelStandard(@ApiIgnore BookingUparcelDto dto) {
        return consultationOrderAndListService.updateConsultationOrderScheduleUparcelStandard(dto);
    }

    //11.Mark as Delivering(标记为配送中:a.越南病人问诊，选择快递的方式并且现金支付。b.越南病人问诊，标记为已支付时):修改status为9
    @PutMapping("consultation/order/markAsDelivering")
    @ApiOperation("问诊订单的Action按钮的Mark as Delivering")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "booking的ID", required = true, dataType = "string", paramType = "query"),
    })
    public ResponseResult updateConsultationOrderMarkAsDelivering(@ApiIgnore BookingDTO dto) {
        return consultationOrderAndListService.updateConsultationOrderMarkAsDelivering(dto);
    }

    //================以下是consultationList的Action按钮
    //1.Mark as paid(越南病人，选择self pick up或者选择快递并且支付方式为银行卡转账):修改status的4为5，sub_status为0
    @PutMapping("consultation/list/markAsPaid")
    @ApiOperation("问诊列表的Action按钮的Mark as paid")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "booking的ID", required = true, dataType = "string", paramType = "query"),
    })
    public ResponseResult updateConsultationListMarkAsPaid(@ApiIgnore BookingDTO dto) {
        return consultationOrderAndListService.updateConsultationListMarkAsPaid(dto);
    }

    //todo:2.update profile(修改使用的配套，只有在retail并且未支付的情况才可修改，且只能修改一次):修改使用配套信息，重新计算金额(计算金额打todo，跟app接口开发时一起做)
    @PutMapping("consultation/list/updateProfile")
    @ApiOperation("问诊列表的Action按钮的update profile")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "booking的ID", required = true, dataType = "string", paramType = "query"),
    })
    public ResponseResult updateConsultationListUpdateProfile(@ApiIgnore BookingDTO dto) {
        return consultationOrderAndListService.updateConsultationListUpdateProfile(dto);
    }


    @GetMapping("consultation/list/medicationCertificationPdf")
    @ApiOperation("问诊列表info里面的Base里面的Medication certification的PDF下载")
    public ResponseResult downloadMedicationCertificationPdf(HttpServletResponse response, String bookingId) {
        return consultationOrderAndListService.downloadMedicationCertificationPdf(response, bookingId);
    }

    @GetMapping("consultation/grab/findListByBookingId")
    @ApiOperation("grab快递信息查询-根据bookingId")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "bookingId", value = "booking的ID", required = true, dataType = "string", paramType = "query"),
    })
    public ResponseResult<List<BookingGrabListVo>,Object> findGrabListByBookingId(@ApiIgnore BookingGrabDto dto) {
        return consultationOrderAndListService.findGrabListByBookingId(dto);
    }

    @GetMapping("consultation/Uparcel/findListByBookingId")
    @ApiOperation("Uparcel快递信息查询-根据bookingId")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "bookingId", value = "booking的ID", required = true, dataType = "string", paramType = "query"),
    })
    public ResponseResult<List<BookingUparcelListVo>,Object> findUparcelListByBookingId(@ApiIgnore BookingUparcelDto dto) {
        return consultationOrderAndListService.findUparcelListByBookingId(dto);
    }


}
